﻿@inherits ComponentBase
@using GMS.NET.Dto.System.Custs.Shared

<Form>
    <FormItem>
        <BootstrapInput @bind-Value="@Context.Cust_FullName" IsTrim="true" />
    </FormItem>
    <FormItem>
        <BootstrapInput @bind-Value="@Context.Cust_Name" IsTrim="true" ValidateRules="CustsDataRules" />
    </FormItem>
    <FormItem>
        <Select @bind-Value="@Context.Cust_Status" ValidateRules="CustsDataRules" />
    </FormItem>
    <FormItem>
        <Select @bind-Value="@Context.Cust_Type" />
    </FormItem>
    <FormItem>
        <BootstrapInput @bind-Value="@Context.Cust_Address" IsTrim="true" />
    </FormItem>
    <FormItem>
        <BootstrapInput @bind-Value="@Context.Cust_Email" IsTrim="true" />
    </FormItem>
    <FormItem>
        <BootstrapInput @bind-Value="@Context.Cust_Phone" IsTrim="true" />
    </FormItem>
    <FormItem Cols="12">
        <Textarea @bind-Value="@Context.Cust_Remark" rows="3" />
    </FormItem>
</Form>

@code {
    [Parameter]
    public CustsData Context { get; set; }

    private List<IValidator> CustsDataRules { get; } = new();
    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();
        CustsDataRules.Add(new FormItemValidator(new FormVaildationAttribute((value,context) =>
        {
            switch (context.MemberName)
            {
                case "Cust_Name":
                    var Instance = context.ObjectInstance as CustsData;
                    return (!(string.IsNullOrWhiteSpace(Instance!.Cust_FullName) || !Instance.Cust_FullName.Contains((value as string)!)),
                    "客户简称仅能从客户全称中选取");
                case "Cust_Status":
                        return (!((Dto.System.Custs.Enums.Cust_Status)value == Dto.System.Custs.Enums.Cust_Status.delete),
                    "不可选择该状态");
            }
            return FormVaildationResult.Success;
        })));
    }
}
